
package com.kugou.game.sdk.ui.dialog;

import com.kugou.game.sdk.utils.Rx;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

/**
 * 描述:礼包淘号成功对话框
 * 
 * @author allenli
 * @since 2014-8-18 下午2:53:11
 */
@SuppressLint("NewApi")
public class GiftMessageDialog extends Dialog {
    TextView mTv_code;

    TextView mTv_ok;

    Button mBtn_copy;

    String mCode;// 礼包号码

    public GiftMessageDialog(Context context) {
        super(context, Rx.style.kg_KYTheme_Widget_Dialog);
        // requestWindowFeature(Window.FEATURE_NO_TITLE);
    }

    public GiftMessageDialog(Context context, String code) {
        super(context, Rx.style.kg_KYTheme_Widget_Dialog);
        // requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.mCode = code;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCanceledOnTouchOutside(false);
        int layoutId = Rx.layout.kg_layout_gift_message_dialog;
        setContentView(layoutId);
        mTv_code = (TextView) findViewById(Rx.id.kg_gift_dialog_tv_code);
        mTv_ok = (TextView) findViewById(Rx.id.kg_gift_dialog_bottom_tv);
        mBtn_copy = (Button) findViewById(Rx.id.kg_gift_dialog_button_copy);
        if (!TextUtils.isEmpty(mCode)) {
            mTv_code.setText(mCode);
        }
        mBtn_copy.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                copy(mTv_code.getText().toString(), getContext());
                Toast.makeText(getContext(), "复制成功", Toast.LENGTH_SHORT).show();
            }
        });
        mTv_ok.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }

    /**
     * 实现文本复制功能
     * 
     * @param content
     */
    public void copy(String content, Context context) {
        // 得到剪贴板管理器
        ClipboardManager cmb = (ClipboardManager) context
                .getSystemService(Context.CLIPBOARD_SERVICE);
        cmb.setText(content.trim());
    }
}
